﻿package mortal.game.view.copy.crossMainCity.mainCityPosition
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.*;
    import mortal.mvc.core.*;

    public class MainCityPostAppointPanel extends GSprite
    {
        private var _bg:GImageBitmap;
        private var _postList:GTileList;
        private var _3dRotationSp:GSprite;
        private var _3dRotationBm:GBitmap;
        protected var _effectPlayer:EffectPlayer;
        protected var _rolePlayer:UserModelPlayer;
        protected var _img2d:Img2D;
        protected var _rect3d:Rect3DObject;
        private var _window:Window;
        private var _startX:Number;
        private var _endX:Number;

        public function MainCityPostAppointPanel(param1:Window)
        {
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._3dRotationSp = UICompomentPool.getUICompoment(GSprite);
            this._3dRotationSp.x = 9;
            this._3dRotationSp.y = 67;
            this._3dRotationSp.mouseEnabled = true;
            this._window.contentTopOf3DSprite.addChild(this._3dRotationSp);
            this._3dRotationBm = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._3dRotationBm.width = 329;
            this._3dRotationBm.height = 543;
            this._3dRotationSp.addChild(this._3dRotationBm);
            this.pushUIToDisposeVec(UIFactory.bg(3, -1, 328, 545, this, ImagesConst.ComboBg));
            this.pushUIToDisposeVec(UIFactory.bg(335, -1, 545, 545, this, ImagesConst.ComboBg));
            this.pushUIToDisposeVec(UIFactory.bg(335, 0, 545, 22, this, ImagesConst.RegionTitleBg));
            this._postList = UIFactory.tileList(327, 25, 550, 490, this);
            this._postList.columnWidth = 545;
            this._postList.rowHeight = 92;
            this._postList.verticalGap = 5;
            this._postList.setStyle("cellRenderer", MainCityPostAppointRender);
            this._postList.configEventListener(Event.CHANGE, this.tabBarChangeHandler);
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21412), 366, 0, 100, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21413), 545, 0, 100, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21414), 670, 0, 100, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21415), 760, 0, 100, 20, this, _loc_1));
            this._bg = UIFactory.gImageBitmap("", 0, 0, null, this.add2d);
            NetDispatcher.addCmdListener(ServerCommand.MainCityPostionInfoGet, this.updatePrivoder);
            GameProxy.guild.getMainCityPostionInfo();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MainCityPostionInfoGet, this.updatePrivoder);
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            Global.stage.removeEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
            this._3dRotationBm.dispose(param1);
            this._3dRotationBm = null;
            this._3dRotationSp.dispose(param1);
            this._3dRotationSp = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._postList.dispose(param1);
            this._postList = null;
            if (this._img2d)
            {
                this._img2d.dispose();
                this._img2d = null;
            }
            if (this._rolePlayer)
            {
                this._rect3d.disposeObj3d(this._rolePlayer);
                this._rolePlayer = null;
            }
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function tabBarChangeHandler(event:Event = null) : void
        {
            var _loc_3:SMiniPlayer = null;
            var _loc_4:int = 0;
            var _loc_5:TTitle = null;
            var _loc_2:* = this._postList.selectedItem.info as SMainCityPositon;
            if (_loc_2)
            {
                _loc_3 = _loc_2.officer;
                if (this._rect3d)
                {
                    if (this._rolePlayer == null)
                    {
                        this._rolePlayer = FrObjectPool.getObject(RoleModelPlayer, this);
                    }
                    _loc_4 = MainCityCache.getPostionClothIdByType(_loc_2.positon);
                    this._rolePlayer.updateIsShowEffect(true, true, true);
                    this._rolePlayer.updateInfo(_loc_3.career, _loc_3.sex, _loc_4, 0, 0, 0, _loc_3.VIP, true);
                    this._rolePlayer.scaleAll = 2;
                    this._rolePlayer.setRenderList(this._rect3d.renderList);
                    this._rolePlayer.rotationY = 0;
                    this._rect3d.addObject3d(this._rolePlayer, 160, 190 + 255);
                    _loc_5 = TitleConfig.instance.getInfoById(200200 + _loc_2.positon - 1);
                    if (this._effectPlayer)
                    {
                        this._rect3d.disposeObj3d(this._effectPlayer);
                    }
                    this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_5.icon, null, this._rect3d.renderList, false);
                    this._effectPlayer.play();
                    var _loc_6:int = 1;
                    this._effectPlayer.scaleZ = 1;
                    var _loc_6:* = _loc_6;
                    this._effectPlayer.scaleY = _loc_6;
                    this._effectPlayer.scaleX = _loc_6;
                    this._rect3d.addObject3d(this._effectPlayer, 160, 145);
                }
            }
            else
            {
                if (this._rolePlayer)
                {
                    this._rect3d.disposeObj3d(this._rolePlayer);
                    this._rolePlayer = null;
                }
                if (this._effectPlayer)
                {
                    this._rect3d.disposeObj3d(this._effectPlayer);
                    this._effectPlayer = null;
                }
            }
            return;
        }// end function

        private function startTurn(event:MouseEvent) : void
        {
            this._startX = this.mouseX;
            this._3dRotationSp.configEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        private function stopTurn(event:MouseEvent) : void
        {
            this._3dRotationSp.removeEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        private function turning(event:MouseEvent) : void
        {
            if (this._rolePlayer)
            {
                this._endX = this.mouseX;
                this._rolePlayer.rotationY = this._rolePlayer.rotationY - (this._endX - this._startX) / 3;
                this._startX = this._endX;
            }
            return;
        }// end function

        private function add2d() : void
        {
            var _loc_1:BitmapData = null;
            if (this.isDisposed)
            {
                return;
            }
            this.add3d();
            this._postList.selectedIndex = this._postList.selectedIndex == -1 ? (0) : (this._postList.selectedIndex);
            this.tabBarChangeHandler();
            Global.stage.addEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            if (this._rect3d)
            {
                _loc_1 = this._bg.bitmapData;
                this._img2d = new Img2D(null, _loc_1, new Rectangle(0, 0, 329, 543), false);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        private function add3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(9, 67, 329, 543), this._window);
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        public function updatePrivoder(param1:Object) : void
        {
            var _loc_3:SMainCityPositon = null;
            var _loc_4:Boolean = false;
            var _loc_2:* = new DataProvider();
            _loc_3 = Cache.instance.mainCity.getPostionByPosType(EMainCityPosition._EMainCityKing);
            if (_loc_3 && EntityUtil.isSelf(_loc_3.officer.entityId))
            {
                _loc_4 = true;
            }
            var _loc_5:int = 5;
            while (_loc_5 > 0)
            {
                
                _loc_3 = Cache.instance.mainCity.getPostionByPosType(_loc_5);
                param1 = {postType:_loc_5, info:_loc_3, isSelfKing:_loc_4};
                _loc_2.addItem(param1);
                _loc_5 = _loc_5 - 1;
            }
            this._postList.dataProvider = _loc_2;
            this._bg.imgUrl = ImagesConst.MainCityPostRoleBg;
            return;
        }// end function

    }
}
